import { state } from './store'

let index = 0
const data = []

window.data = data

// 操作保存的数据
export const saveData = () => {
  const json = state.canvas.toDatalessJSON()
  data[index] = json
  index++
  console.log(data)
}
// 上一步操作
export const prev = () => {
  if (index < 0) {
    index = -1
    state.canvas.clear()
  } else {
    const json = data[index--]
    console.log(json)
    state.canvas.loadFromJSON(json, (e) => {
      console.log('load')
    })
    state.canvas.renderAll()
  }
}

export const forward = () => {
  if (index + 1 >= data.length) {
    index = data.length - 1
  } else {
    const json = data[index++]
    state.canvas.loadFromJSON(json)
    state.canvas.renderAll()
  }
}
